﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Data.OleDb;
using System.IO;

namespace DiaryPlanner
{
    public partial class AlbumPhoto : PictureBox
    {
        public ContextMenu photoMenu = new ContextMenu();
        public Album thisAlbumObject;
        public String photoName;//*****************파일명(id)
        public String photoMemo;//contents

        public AlbumPhoto(Album ab)
        {
            thisAlbumObject = ab;
            photoMenu.MenuItems.Add("삭제", deletePhoto);
            InitializeComponent();
        }

        public void deletePhoto(object sender, EventArgs e)
        {
            //해당 사진을 삭제
            thisAlbumObject.nowFolder.PhotoList.Remove(this);
            thisAlbumObject.nowPhoto = null;
            //thisAlbumObject.photoPanel.Controls.Remove(this);
            thisAlbumObject.viewAllPhoto();
            this.Image = null;

            //디렉토리에서 사진  삭제
            GC.Collect();
            try
            {
                File.Delete("./Album/" + thisAlbumObject.nowFolder.realName + "/" + photoName);
            }
            catch{ 
            
            }
        }
        

        private void AlbumPhoto_Click(object sender, EventArgs e)
        {
            thisAlbumObject.nowPhoto = this;
            PhotoViewer pv = new PhotoViewer(thisAlbumObject);
            pv.ShowDialog();
        }

        private void AlbumPhoto_MouseDown(object sender, MouseEventArgs e)
        {
            //mouse down 왼쪽 이벤트는 처리하지 않음
            if ((e.Button & MouseButtons.Left) == MouseButtons.Left) return;

            //오른쪽 마우스 down 이벤트만 처리


            //이 사진을 삭제한다
            thisAlbumObject.nowPhoto = this;
            Point m = this.PointToClient(new Point(Control.MousePosition.X, Control.MousePosition.Y));
            photoMenu.Show(this, m);
        }
    }
}
